package cn.smdq.ch.code.generator.modules;

import cn.smdq.ch.code.generator.config.GenerationConfigBuilder;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;

/**
 * @author shuimodanqing
 * create at:  2019/1/24  2:12 PM
 * @description API网关路由实体生成代码
 */
public class GateWayGenerator {

    public static void execute() {
        AutoGenerator mpg = new AutoGenerator();

        //1. 构建代码生成的输出路径
        String outputDir = GenerationConfigBuilder.buildOutputDir("hope-gateway");
        //2. 全局配置
        GlobalConfig gc = GenerationConfigBuilder.buildGlobalConfig(outputDir + "/src/main/java");
        //3. 策略配置 - 包含的表
        String[] includeTable =
                new String[]{"system_routes"};
        StrategyConfig sc = GenerationConfigBuilder.buildStrategyConfig("system", null, null, null, includeTable);
        //4. 包配置
        PackageConfig pc = GenerationConfigBuilder.buildPackageConfig("cn.smdq.ch.gateway.core.route");
        //5. 数据源配置
        DataSourceConfig dsc = GenerationConfigBuilder.buildDataSourceConfig();
        //6. 自定义mapper.xml输出目录
        InjectionConfig cfg = GenerationConfigBuilder.buildInjectionConfig(outputDir);
        //7. 开始构建
        mpg.setDataSource(dsc);
        mpg.setStrategy(sc);
        mpg.setPackageInfo(pc);
        mpg.setGlobalConfig(gc);
        mpg.setCfg(cfg);
        // 取消默认的xml生成模版
        mpg.setTemplate(new TemplateConfig().setXml(null));
        //8. 开始执行
        mpg.execute();
    }

}
